﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraEditors;
using System.Threading;

namespace Computer_Manager.GUI
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        frmCustomer frmCus = null; frmAddOrder frmAddOrder = null;
        frmCompany frmDis = null; frmOrder frmOrder = null;
        frmUser frmUser = null; frmProduct frmPro = null;
        frmCategories frmcate = null; frmStatistic frmstatis = null;
        public frmMain()
        {
            InitializeComponent();
            InitSkinsGallery();
        }
        void InitSkinsGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins,true);
        }

        public DataTable User { get;set;}

        private void frmMain_Load(object sender, EventArgs e)
        {
            checkrole(User.Rows[0]["role_id"].ToString());
            barSNameUser.Caption = User.Rows[0]["fullname"].ToString();
        }

        private void checkrole(string role)
        {
            if (role == "2")
            {
                bbtnNguoidung.Enabled = false;
                bbtnSaoLuu.Enabled = false;
                bbtnPhucHoi.Enabled = false;

            }
        }
        private void bbtnKhachHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            if (frmCus == null || frmCus.IsDisposed)
            {
                frmCus = new frmCustomer();
                frmCus.MdiParent = this;
                frmCus.Show();
            }
            else
            {
                frmCus.Activate();
            }
            splashScreenManager1.CloseWaitForm();
                        
        }

        private void bbtnNhaPhanPhoi_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (frmDis == null || frmDis.IsDisposed)
            {
                frmDis = new frmCompany();
                frmDis.MdiParent = this;
                frmDis.Show();
            }
            else
            {
                frmDis.Activate();
            }
        }

        private void bbtnNguoidung_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (frmUser == null || frmUser.IsDisposed)
            {
                frmUser = new frmUser();
                frmUser.MdiParent = this;
                frmUser.Show();
            }
            else
            {
                frmUser.Activate();
            }
        }

        private void bbtnDoiMatKhau_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmChangePass changepass = new frmChangePass();
            changepass.idu = int.Parse(User.Rows[0]["id_user"].ToString());
            changepass.ShowDialog();
        }

        private void bbtnInfo_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmInfoCompany infoCom = new frmInfoCompany();
            infoCom.ShowDialog();
        }

        private void bbtnThoat_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (DialogResult.Yes == XtraMessageBox.Show("Bạn có chắc muốn thoát chương trình.","Thông tin",MessageBoxButtons.YesNo,MessageBoxIcon.Warning))
            {
                //Application.Exit();
                this.Hide();
                frmLogin frmLogin = new frmLogin();
                frmLogin.Show();
            }
        }

        
        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult.No == XtraMessageBox.Show("Bạn có chắc muốn thoát chương trình.", "Thông tin", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
            {
                e.Cancel = true;
            }            
        }

        private void bbtnNhapHoaDon_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            if (frmAddOrder == null || frmAddOrder.IsDisposed)
            {
                frmAddOrder = new frmAddOrder();
                int id_user = int.Parse(User.Rows[0]["id_user"].ToString());
                frmAddOrder.id_user = id_user;
                frmAddOrder.MdiParent = this;
                frmAddOrder.Show();
            }
            else
            {
                frmAddOrder.Activate();
            }
            splashScreenManager1.CloseWaitForm();
        }

        private void btnOrder_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            if (frmOrder == null || frmOrder.IsDisposed)
            {
                frmOrder = new frmOrder();
                frmOrder.MdiParent = this;
                frmOrder.Show();
            }
            else
            {
                frmOrder.Activate();
            }
            splashScreenManager1.CloseWaitForm();
        }

        private void bbtnSaoLuu_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmBackupDB frmBak = new frmBackupDB();
            frmBak.ShowDialog();
        }


        private void btnProduct_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            if (frmPro == null || frmPro.IsDisposed)
            {
                frmPro = new frmProduct();
                frmPro.MdiParent = this;
                frmPro.Show();
            }
            else
            {
                frmPro.Activate();
            }
            splashScreenManager1.CloseWaitForm();
        }

        private void btnCate_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            if (frmcate == null || frmcate.IsDisposed)
            {
                frmcate = new frmCategories();
                frmcate.MdiParent = this;
                frmcate.Show();
            }
            else
            {
                frmcate.Activate();
            }
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            if (frmstatis == null || frmstatis.IsDisposed)
            {
                frmstatis = new frmStatistic();
                frmstatis.MdiParent = this;
                frmstatis.Show();
            }
            else
            {
                frmstatis.Activate();
            }
            splashScreenManager1.CloseWaitForm();
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
        }

>>>>>>> .r38
        
        
    }
}